package priv.pront.code.national.acwing.base;

import java.io.*;

/**
 * @Description:
 * @Author: pront
 * @Time:2023-05-23 19:23
 */
public class Acwing831_kmp字符串 {
    static int n, m;
    static char[] p = new char[100010], s = new char[1000010];
    static int[] ne = new int[100010];

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine());

        String sp = br.readLine();
        int m = Integer.parseInt(br.readLine());
        String ss = br.readLine();

        for (int i = 1; i <= n; i++) {
            p[i] = sp.charAt(i - 1);
        }

        for (int i = 1; i <= m; i++) {
            s[i] = ss.charAt(i - 1);
        }

        //ne
        for (int i = 2, j = 0; i <= n; i++) {
            while (j != 0 && p[i] != p[j + 1]) j = ne[j];
            if (p[i] == p[j + 1]) j++;
            ne[i] = j; //当前点匹配，则记录当前点的下一个点j(j++)在模板中的位置
        }

        for (int i = 1, j = 0; i <= m; i++) {
            while (j != 0 && s[i] != p[j + 1]) j = ne[j];
            if (s[i] == p[j + 1]) j++;
            if (j == n) {
                bw.write(i - n + " ");
                j = ne[j];
            }
        }
        bw.flush();
        bw.close();
        br.close();

    }
}
